﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Windows.Forms;

namespace _201206QuanLyBanHang.DanhMuc
{
    class BLL_Xetdautu
    {
         DataConn da;
         public BLL_Xetdautu()
        {
            da = new DataConn();
        }
         public DataSet getdautu(string strsql)
        {
            return da.ExectueQueryDataset(strsql, CommandType.Text, null);
        }
         public bool insertxetdautu(ref string err, int madt,int makh,DateTime ngaydautu,double tongdautu,string ghichu)
        {
            return da.MyExecuteNonQuery("Pro_Insert_Duocdt", CommandType.StoredProcedure, ref err, new SqlParameter("@madautu", madt), new SqlParameter("@makh", makh),new SqlParameter("@ngaydt",ngaydautu),new SqlParameter("@tongdautu",tongdautu), new SqlParameter("@ghichu",ghichu));
        }
        public bool deletexetdautu(ref string err, int Madt, int makh)
        {
            return da.MyExecuteNonQuery("Pro_Delete_Duocdt", CommandType.StoredProcedure, ref err, new SqlParameter("@Madautu", Madt),new SqlParameter("@makh", makh));
        }
        public bool updateXetdautu(ref string err, int madt, int makh, DateTime ngaydautu, double tongdautu, string ghichu)
        {
            return da.MyExecuteNonQuery("Pro_Update_Duocdt", CommandType.StoredProcedure, ref err, new SqlParameter("@madautu", madt), new SqlParameter("@makh", makh), new SqlParameter("@ngaydt", ngaydautu), new SqlParameter("@tongdautu", tongdautu), new SqlParameter("@ghichu", ghichu));
        }
        public void fillCombo(string sql, ComboBox cmb, string text, string value)
        {
            DataSet ds = new DataSet();
            ds = da.ExectueQueryDataset(sql, CommandType.Text, null);

            cmb.DataSource = ds.Tables[0];
            cmb.DisplayMember = text;
            cmb.ValueMember = value;
            cmb.SelectedIndex = -1;
        }
        public float laytongtien(string err,string sql)
        {
            float tong = 0;
            tong = da.getGia_Vt(sql, CommandType.Text, ref err);
            return tong;
        }
        public DataTable LayThongtinTimkiem(String makhuvuc, String tenkhachhang)
        {
            String sql = "select a.makh,tenkh,tencuahang,b.madautu from khachhang a left join kh_duoc_dt b on a.makh=b.makh  where makhuvuc='" + makhuvuc + "'and dbo.fnChuyenKhongDau(Tencuahang) like '%" + tenkhachhang + "%'";
           
            return da.GetDataTable(sql);
        }
    }
}
